package com.ethanzzh.ethanzzh_xdclass.controller;

import com.ethanzzh.ethanzzh_xdclass.config.WeChatConfig;
import com.ethanzzh.ethanzzh_xdclass.mapper.VideoMapper;
import com.ethanzzh.ethanzzh_xdclass.model.pojo.Video;
import com.ethanzzh.ethanzzh_xdclass.service.ExcelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class TestController {


    @RequestMapping("/test")
    public String test() {
        return "hello";
    }


    @Autowired
    private WeChatConfig weChatConfig;

    @RequestMapping("/test_config")
    public String testConfig( ) {

        System.out.println(weChatConfig.getAppId());
        return "hello";
    }

    @Autowired
    private VideoMapper videoMapper;

    @RequestMapping("/test_db")
    public Object testDB( ) {


        System.out.println(weChatConfig.getAppId());
        return videoMapper.findVideos();
    }


    @Autowired
    private ExcelService excelService;

    @PostMapping("/import")
    public boolean addUser(@RequestParam("file") MultipartFile file) {
        boolean a = false;
        String fileName = file.getOriginalFilename();
        try {
            a = excelService.batchImport(fileName, file);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  a;
    }


}
